package com.hustcad.plm.pdm.user.service.impl;


import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.user.mapper.PlmPartMapper;
import com.hustcad.plm.pdm.user.service.PlmPartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


@Service
public class PlmPartServiceImpl implements PlmPartService {
    @Autowired
    PlmPartMapper plmPartMapper;


    @Override
    public Integer add(Map<String, Object> map) {
        return plmPartMapper.add(map);
    }

    @Override
    public List<Map<String,Object>> list(Map<String, Object> map) {
        return plmPartMapper.list(map);
    }

    @Override
    public Integer edit(Map<String, Object> map) {
        return plmPartMapper.edit(map);
    }

    @Override
    public Integer delete(Map<String, Object> map) {
        return plmPartMapper.delete(map);
    }

    @Override
    public Integer addLink(Map<String, Object> map) {
        return plmPartMapper.addLink(map);
    }

    @Override
    public Integer editLink(Map<String, Object> map) {
        return plmPartMapper.editLink(map);
    }

    @Override
    public List<Map<String, Object>> plmPartDataType(Map<String, Object> map) {
        return plmPartMapper.plmPartDataType(map);
    }

    @Override
    public List<Map<String, Object>> plmPartValuationType(Map<String, Object> map) {
        return plmPartMapper.plmPartValuationType(map);
    }

    @Transactional
    @Override
    public Integer addInPartOption(List<Map<String, Object>> list) {
        return plmPartMapper.addInPartOption(list);
    }

    @Override
    public Integer deleteInPartOption(Map<String, Object> map) {
        return plmPartMapper.deleteInPartOption(map);
    }

    @Override
    public List<Map<String, Object>> getInPartOption(Map<String, Object> map) {
        return plmPartMapper.getInPartOption(map);
    }

    @Override
    public Integer addOutPartOption(List<Map<String, Object>> list) {
        return plmPartMapper.addOutPartOption(list);
    }

    @Override
    public Integer deleteOutPartOption(Map<String, Object> map) {
        return plmPartMapper.deleteOutPartOption(map);
    }

    @Override
    public List<Map<String, Object>> getOutPartOption(Map<String, Object> map) {
        return plmPartMapper.getOutPartOption(map);
    }

    @Override
    public Integer addOutPartLink(List<Map<String, Object>> list) {
        return plmPartMapper.addOutPartLink(list);
    }

    @Override
    public Integer deleteOutPartLink(Map<String, Object> map) {
        return plmPartMapper.deleteOutPartLink(map);
    }

    @Transactional
    @Override
    public void submitInPlmPart(Map<String,Object> map, List<Map<String, Object>> inList) {
        for(int i=0;i<inList.size();i++){
            inList.get(i).put("plm_source_type_id",map.get("id"));
        }
        Map<String, Object> d= new HashMap<>();
        d.put("plm_source_type_id",map.get("id"));
        deleteInPartOption(d);
        if(inList.size()>0){
            addInPartOption(inList);
        }
    }

    @Transactional
    @Override
    public void submitOutPlmPart(Map<String, Object> map,List<Map<String,Object>> outList) {
        for(int i=0;i<outList.size();i++){
            outList.get(i).put("k3cloud_setting_id",map.get("id"));
        }
        Map<String, Object> d= new HashMap<>();
        d.put("k3cloud_setting_id",map.get("id"));
        deleteOutPartOption(d);
        addOutPartOption(outList);
    }
    @Transactional
    @Override
    public void setPlmPartLink(Map<String, Object> map) {
        List<Map<String, Object>> list=new ArrayList<>();
        List<String>  plmIds= (List<String>) map.get("plmIds");
        map.put("k3cloud_setting_id",map.get("id"));
        if(plmIds.size()>0){
            deleteOutPartLink(map);
            for(int i=0;i<plmIds.size();i++){
                Map<String,Object> add=new HashMap<>();
                add.put("id", UUID.randomUUID().toString());
                add.put("k3cloud_setting_id",map.get("id"));
                add.put("plm_source_type_id",plmIds.get(i));
                list.add(add);
            }
            addOutPartLink(list);
        }
        else{
            deleteOutPartLink(map);
        }
    }

    @Override
    public List<Map<String, Object>> getPlmPartLink(Map<String, Object> map) {
        return plmPartMapper.getPlmPartLink(map);
    }

    @Override
    public Integer addPlmSourceType(Map<String, Object> map) {
        return plmPartMapper.addPlmSourceType(map);
    }

    @Override
    public List<Map<String, Object>> getPlmSourceType(Map<String, Object> map) {
        return plmPartMapper.getPlmSourceType(map);
    }

    @Override
    public Integer deletePlmSourceType(Map<String, Object> map) {
        return plmPartMapper.deletePlmSourceType(map);
    }

    @Override
    public Integer editPlmSourceType(Map<String, Object> map) {
        return plmPartMapper.editPlmSourceType(map);
    }

    @Override
    public Integer editInPartOptionById(Map<String, Object> map) {
        return plmPartMapper.editInPartOptionById(map);
    }

    @Override
    public Integer addInPartOptionById(Map<String, Object> map) {
        return plmPartMapper.addInPartOptionById(map);
    }

    @Override
    public Integer deleteInPartOptionById(Map<String, Object> map) {
        return plmPartMapper.deleteInPartOptionById(map);
    }

    @Override
    public Integer addOutPartOptionById(Map<String, Object> map) {
        return plmPartMapper.addOutPartOptionById(map);
    }

    @Override
    public Integer deleteOutPartOptionById(Map<String, Object> map) {
        return plmPartMapper.deleteOutPartOptionById(map);
    }


}
